import Taro from '@tarojs/taro'
import { getBanners, getClassify, getStores, getCategory } from './service';

export default {

  namespace: 'home',

  state: {},

  effects: {
    * init(action, { call, put,  all}) {
      console.log('home effects init');
      const [banners,classify,stores,category] = yield all([
        call(getBanners),
        call(getClassify),
        call(getStores),
        call(getCategory),
      ]);
      console.log('home effects banners',banners);
      console.log('home effects classify',classify);
      console.log('home effects stores',stores);
      console.log('home effects category',category);
      yield put({
        type:'save',
        payload: {
          banners:banners.list,
          classify:classify.list,
          stores:stores.list,
          category:category.list,
        },
      });
    },

  },

  reducers: {
    save(state, { payload }) {
      console.log('home effects payload',payload);
      return {
        ...state,
        ...payload
      };
    },
  },
};
